package net.sky.oa.util;

import java.io.UnsupportedEncodingException;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.tempuri.WmgwLocator;

public class SmsTool {
	private static WmgwLocator wmgwLocator = null;
	private static final String userid = "J00333";
	private static final String pwd = "147258";
	
	/**
	 * 1、短信发送：客服网关，群发信息
	 * @param mobiles
	 * @param content
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public int smsSend(String mobiles,String content,int iMobiCount) throws UnsupportedEncodingException {
		wmgwLocator = new WmgwLocator();
		int num = 0;
		try {
			num = wmgwLocator.getwmgwSoap().mongateCsSendSmsEx(userid,pwd, mobiles, content,iMobiCount).length();
			System.out.println("群发成功！");
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e){
			e.printStackTrace();
		}
		return num;
	}
	/**
	 * 2、短信发送：支持长信息
	 * @param mobiles
	 * @param content
	 * @param port
	 * @return
	 * @throws ServiceException
	 */
	public int smsSendLong(String mobiles,String content,int iMobiCount,String port) {
		wmgwLocator = new WmgwLocator();
		int num = 0;
		try {
			num = wmgwLocator.getwmgwSoap().mongateCsSpSendSmsNew(userid,pwd, mobiles, content,iMobiCount,port).length();
			System.out.println("长短信发送成功！");
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e){
			e.printStackTrace();
		}
		return num;
	}
	/**
	 * 3、查询余额
	 * @return
	 * @throws ServiceException
	 */
	public int queryBalance() throws ServiceException {
		wmgwLocator = new WmgwLocator();
		int num = 0;
		try {
			num = wmgwLocator.getwmgwSoap().mongateQueryBalance(userid,pwd);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return num;
	}
	/**
	 * 4、接收短信回复
	 * @throws RemoteException
	 * @throws ServiceException
	 */
	public void mongateCsGetSmsEx(){
		wmgwLocator = new WmgwLocator();
		try {
			String[] strRet = wmgwLocator.getwmgwSoap().mongateCsGetSmsExEx(userid, pwd);
			if (strRet != null){
				for(int i = 0; i < strRet.length; ++i){
					System.out.println(strRet[i]);
				}
			}else{
				System.out.println("无上行信息！");
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 5、获取状态报告
	 * @throws ServiceException
	 * @throws RemoteException
	 */
	public void mongateCsGetStatusReportEx(){
		wmgwLocator = new WmgwLocator();
		try {
			System.out.println("Test mongateCsGetStatusReportExEx ...");
			String[] strRet = wmgwLocator.getwmgwSoap().mongateCsGetStatusReportExEx(userid, pwd);
			if (strRet != null){
				for(int i = 0; i < strRet.length; ++i){
					System.out.println(strRet[i]);
				}
			}else{
				System.out.println("无上行信息！");
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (ServiceException e) {
			e.printStackTrace();
		}
	}
	
//	public static void main(String[] args) throws RemoteException, ServiceException {
//		SmsTool st = new SmsTool();
//		st.mongateCsGetSmsEx();
//		int i = st.smsSendLong("15986656534,13168015577", "测试信息1请", 2, "888");
//		System.out.println(i);
//		st.mongateCsGetStatusReportEx();
//		System.out.println(st.queryBalance());
//	}
}
